namespace PickGold.Charting
{
    using System;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Security.Permissions;
    using System.Web;

    [SRDescription("DescriptionAttributeMapAreasCollection_MapAreasCollection"), AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    public class MapAreasCollection : ChartElementCollection<MapArea>
    {
        public MapAreasCollection() : base(null)
        {
        }

        internal void InsertPath(int index, string toolTip, string url, string attributes, string postBackValue, GraphicsPath path, bool absCoordinates, ChartGraphics graph)
        {
            GraphicsPathIterator iterator = new GraphicsPathIterator(path);
            if (iterator.SubpathCount > 1)
            {
                GraphicsPath path2 = new GraphicsPath();
                while (iterator.NextMarker(path2) > 0)
                {
                    this.InsertSubpath(index, toolTip, url, attributes, postBackValue, path2, absCoordinates, graph);
                    path2.Reset();
                }
            }
            else
            {
                this.InsertSubpath(index, toolTip, url, attributes, postBackValue, path, absCoordinates, graph);
            }
        }

        private void InsertSubpath(int index, string toolTip, string url, string attributes, string postBackValue, GraphicsPath path, bool absCoordinates, ChartGraphics graph)
        {
            if (path.PointCount > 0)
            {
                path.Flatten();
                PointF[] pathPoints = path.PathPoints;
                float[] coordinates = new float[pathPoints.Length * 2];
                if (absCoordinates)
                {
                    for (int i = 0; i < pathPoints.Length; i++)
                    {
                        pathPoints[i] = graph.GetRelativePoint(pathPoints[i]);
                    }
                }
                int num2 = 0;
                foreach (PointF tf in pathPoints)
                {
                    coordinates[num2++] = tf.X;
                    coordinates[num2++] = tf.Y;
                }
                MapArea item = new MapArea(MapAreaShape.Polygon, toolTip, url, attributes, postBackValue, coordinates, null);
                item.IsCustom = false;
                base.Insert(index, item);
            }
        }

        internal void RemoveNonCustom()
        {
            for (int i = 0; i < base.Count; i++)
            {
                if (!base[i].IsCustom)
                {
                    base.RemoveAt(i);
                    i--;
                }
            }
        }
    }
}

